import {Button, Text} from 'native-base';
import React, {useCallback, useEffect} from 'react';
import Icon from '../Icon';
import {useLocationStore} from '@/store/locationStore/locationStore';
import {useFocusEffect, useNavigation} from '@react-navigation/native';
import {useReqCoordinate} from '@/utils/requestLocationPermission';

export default function (params: IButtonProps) {
  const {addressName} = useLocationStore();
  const navigation = useNavigation();
  useReqCoordinate();
  const changeLocation = useCallback(() => {
    navigation.navigate('address');
  }, []);

  return (
    <>
      <Button
        {...params}
        variant={'link'}
        size={'auto'}
        leftIcon={
          <Icon
            iconName={'\ue636'}
            size={'auto'}
            fontSize={'20'}
            color={'coolGray.800'}
          />
        }
        onPress={changeLocation}>
        <Text isTruncated color={'coolGray.800'} w={'70'}>
          {addressName}
        </Text>
      </Button>
    </>
  );
}
